<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
	<meta name="format-detection" content="telephone=no, date=no, address=no, email=no, url=no">
	<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
	<meta http-equiv="Pragma" content="no-cache">
	<meta http-equiv="Expires" content="0">
	<meta name="sharecontent" data-msg-title="电子烟管理系统" data-msg-content="电子烟管理系统"
    data-msg-callback="" data-line-img="http://e-cigarette.huan-ju.cn/public/Uploads/2017-12-24/5a3fc4833b4f6.jpg"
    data-line-title="电子烟管理系统" data-line-callback="" />
	<title>门店首页</title>
	<meta name="description" content="">
	<link rel="stylesheet" href="/public/home/css/main.css">
	<script type="text/javascript">
		(function (win, doc) {
			if (!win.addEventListener) return;
			var html = document.documentElement;
			function setFont() {
				var cliWidth = html.clientWidth;
				html.style.fontSize = 100 * (cliWidth / 750) + 'px';
			}
			win.addEventListener('resize', setFont, false);
			setFont();
		})(window, document);
	</script>
</head>

<body>
	<div class="container">
		<div class="head">
			<div class="PersonalImgNav">
				<img src="http://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eqYkgC8c6ZVcZ5MVYWyVnG12vDBnAH0GpmhZkDqb7S4mUfk3hL3SxlIlSHsomPdzZpo2C8dYZNx8g/132" />
			</div>
			<div class="map-text">
				您所在位置<br />
				<p>门店1</p>
			</div>
		</div>
		<form method="POST">
			<div class="shop-content">
				<h1>请填写您要购买的数量</h1>
								<div class="YH">
					<img src="/public/uploads/20181122\43214e3ecde93c1438744c36e0caf3e7.jpg" />
					<div>
						烟杆1&nbsp;<i>￥</i>
						<a>0.10</a>
						<br />
						<ul>
							<li class="reduce">-</li>
							<li class="input-text">
								<input name="goods_store_id[]" type="hidden" value="1" />
								<input name="goods_id[]" type="hidden" value="1" />
								<input name="price[]" type="hidden" value="0.10" />
								<input name="goods_num[]" class="goods_num" type="number" data-price="0.10" pattern="\d*" value="1" />
							</li>
							<li class="add">+</li>
						</ul>
					</div>
				</div>
								<input type="hidden" name="seat_id" value="1">
				<input type="hidden" name="store_id" value="1">
				<hr />
				<p class="money">
					合计金额：<i>￥</i>
					<a id="ToMoney" name="Money"></a>
					<input type="hidden" id="total_amount" name="total_amount" value="0.1">
				</p>
			</div>
			<button type="button" class="submit" id="pay_btn">付&nbsp;款</button>
		</form>
	</div>
	<script src="/public/wechat/assets/jquery.min.js"></script>
	<script src="/public/wechat/assets/zepto.min.js"></script>
	<script src="/public/wechat/js/main.js"></script>
	<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
    $(function () {
        wx.config({
            debug: true,
            appId: "wx2c23698c4f2d86ee",
            timestamp: "1544530606",
            nonceStr: "h1ty7hstx9yhprsw",
            signature: 'fd1fea0639ad74d034f046f4c5de4e728b62797b',
            jsApiList: [
                  'checkJsApi',
                  'onMenuShareTimeline',
                  'onMenuShareAppMessage',
                  'startRecord', //需要使用jssdk功能list
                  'stopRecord',
                  'onVoiceRecordEnd',
                  'onVoicePlayEnd',
                  'downloadVoice',
                  'chooseWXPay'
                ]
        });

        wx.ready(function () {
            wx.onMenuShareTimeline({
                title: '电子烟管理系统', // 
                desc: '电子烟管理系统',
                link: 'http://e-cigarette.huan-ju.cn/index.php/wechat/order/index.html?store_id=1&seat_id=1&seat_num=1', // 
                imgUrl: 'http://e-cigarette.huan-ju.cn/public/Uploads/2017-12-24/5a3fc4833b4f6.jpg', // 
                success: function () {

                },
                cancel: function () {
                    alert(window.location.href);
                    // 
                }
            });
            wx.onMenuShareAppMessage({
                title: '电子烟管理系统', // 
                desc: '电子烟管理系统',
                link: 'http://e-cigarette.huan-ju.cn/index.php/wechat/order/index.html?store_id=1&seat_id=1&seat_num=1', // 
                imgUrl: 'http://e-cigarette.huan-ju.cn/public/Uploads/2017-12-24/5a3fc4833b4f6.jpg', // 
                type: 'link', // 
                success: function () {

                },
                cancel: function () {
                    // 
                }
            });
        });
    });
</script>

	<script type="text/javascript">
		var jsApiParameters = {
			"appId": "",     //公众号名称，由商户传入     
			"timeStamp": "",         //时间戳，自1970年以来的秒数     
			"nonceStr": "", //随机串     
			"package": "",
			"signType": "MD5",         //微信签名方式：     
			"paySign": "" //微信签名 
		};
		$(function () {
			$('#pay_btn').click(function () {
				var goods_store_id = new Array(), goods_id = new Array(), price = new Array(), goods_num = new Array();
				var i = 0;
				var seat_id = $('input[name=seat_id]').val();
				var store_id = $('input[name=store_id]').val();
				var total_amount = $('input[name=total_amount]').val();
				var count = 0;
				$('.input-text').each(function () {
					var j = 0;
					$(this).find('input').each(function () {
						switch (j) {
							case 0:
								goods_store_id[i] = $(this).val();
								j++;
								break;
							case 1:
								goods_id[i] = $(this).val();
								j++;
								break;
							case 2:
								price[i] = $(this).val();
								j++;
								break;
							case 3:
								goods_num[i] = $(this).val();
								if (!isNaN(goods_num[i]) && goods_num[i].length > 0 && parseInt(goods_num[i]) > 0) {
									count += parseInt(goods_num[i]);
								}
								j++;
								break;
						}
					});
					i++;
				});
				if (count <= 0) {
					alert('请选择商品');
					return;
				}
				$.ajax({
					url: "/index.php/wechat/order/submitorder.html",
					data: { goods_store_id: goods_store_id, goods_id: goods_id, price: price, goods_num: goods_num, seat_id: seat_id, store_id: store_id, total_amount: total_amount },
					type: "post",
					dataType: "json",
					success: function (res) {
						if (res.status > 0) {
							console.log(res.notify_url);
							jsApiParameters = res.jsApiParameters;
							jsApiCall();
						} else {
							alert(res.msg);
						}
					}
				});
			});
		});
		//调用微信JS api 支付
		function jsApiCall() {
			console.log(jsApiParameters);
			wx.chooseWXPay({
				timestamp: jsApiParameters.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
				nonceStr: jsApiParameters.nonceStr, // 支付签名随机串，不长于 32 位
				package: jsApiParameters.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
				signType: jsApiParameters.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
				paySign: jsApiParameters.paySign, // 支付签名
				success: function (res) {
					alert(JSON.stringify(res));
					if (res.err_msg == "get_brand_wcpay_request:ok") {
						jsApiParameters = {
							"appId": "",     //公众号名称，由商户传入     
							"timeStamp": "",         //时间戳，自1970年以来的秒数     
							"nonceStr": "", //随机串     
							"package": "",
							"signType": "MD5",         //微信签名方式：     
							"paySign": "" //微信签名 
						};
					} else {
						console.log(JSON.stringify(res));
						alert('支付失败！' + res.errDesc + res.errMsg);
					}
				},
				fail: function(res){
					alert(JSON.stringify(res));
				}
			});
		}
	</script>
</body>

</html>